package minidb.parse.exps;

import java.util.*;

public class OrderList
{
	public List<Field> orderList;
	public List<Boolean> descList;
	

	public OrderList()
	{
		this.orderList = new ArrayList<Field>();
		this.descList=new ArrayList<Boolean>();
	}

	public OrderList AddField(Field f,Boolean desc)
	{
		this.orderList.add(f);
		this.descList.add(desc);
		return this;
	}

	public List<Field> GetOrderList()
	{
		return this.orderList;
	}
	
	public List<Boolean> GetDescList()
	{
		return this.descList;
	}
	
	public String Print()
	{
		StringBuilder sb = new StringBuilder("\nORDER BY ");

		for (int i = 0; i < this.orderList.size(); i++)
		{
			Field f = this.orderList.get(i);
			sb.append(f.Print());
			if(this.descList.get(i))
				sb.append(" DESC");
			else
				sb.append(" ASC");
			if (i != this.orderList.size() - 1)
				sb.append(",");
		}
		return sb.toString();
	}
}
